export default {
	data() {
		return {
			actionSheetOption: {
				title: '选择地图应用',
				cancel: '取消',
				// buttons: [{ title: '腾讯地图' }, { title: '百度地图' }, { title: '高德地图' }]
				buttons: [{ title: '高德地图' }]
			}
		}
	},
	methods: {
		openNavigation(data) {
			let location = data.location
			// #ifdef HTML5 || PREVIEW
			// 浏览器则打开网页版地图进行导航
			uni.showModal({
				content: '是否跳转至腾讯地图',
				success: res => {
					if (res.confirm) {
						// addr:手帕口桥北铁路道口
						window.location.href = ` https://apis.map.qq.com/uri/v1/marker?marker=coord:${location[1]},${location[0]};title:${data.title};&referer=xxx`
					}
				}
			})
			// #endif
			// #ifdef APP-PLUS
			this.getMapAPPUrl(location[1],location[0],data.title)
			// let packageName = 'com.tencent.map'
			// let main = plus.android.runtimeMainActivity()
			// let packageManager = main.getPackageManager()
			// let PackageManager = plus.android.importClass(packageManager)
			// let packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
			// if (packageInfo) {
			// 	let Uri = plus.android.importClass('android.net.Uri')
			// 	// addr:手帕口桥北铁路道口
			// 	let url = `qqmap://map/marker?marker=coord:${location[1]},${location[0]};title:${data.title};`
			// 	let Intent = plus.android.importClass('android.content.Intent')
			// 	let intent = new Intent()
			// 	intent.setAction(Intent.ACTION_VIEW)
			// 	intent.addCategory(Intent.CATEGORY_DEFAULT)
			// 	let uri = Uri.parse(url)
			// 	//将功能Scheme以URI的方式传入data
			// 	intent.setData(uri)
			// 	intent.setPackage('com.tencent.map')
			// 	let main = plus.android.runtimeMainActivity()
			// 	main.startActivity(intent)
			// } else {
			// 	// alert('未安装' + packageName + '')
			// 	this.$toast(this.$t('nearby.本机未安装指定的地图应用'))
			// }
			// #endif
			// #ifdef MP-WEIXIN
			// 浏览器则打开网页版地图进行导航
			wx.openLocation({
				type: 'gcj02',
				latitude: location[0],
				longitude: location[1],
				scale: 15,
				name: data.title,
				success: result => {},
				fail: () => {},
				complete: () => {}
			})
			// #endif
			// #ifdef PRIVATE || SUBSCRIPTION
			wx.openLocation({
				latitude: location[0],
				longitude: location[1],
				name: data.title,
				scale: 15
			})
			// #endif
		},

		getMapAPPUrl(latitude, longitude, name) {
			let url = ''
			if (plus.os.name == 'Android') {
				//判断是安卓端

				plus.nativeUI.actionSheet(this.actionSheetOption, (e) => {
					switch (
						e.index //下面是拼接url,不同系统以及不同地图都有不同的拼接字段
					) {
						// case 1: //注意referer=xxx的xxx替换成你在腾讯地图开发平台申请的key
						// 	url = `qqmap://map/marker?marker=coord:${latitude},${longitude};title:${name}`
						// 	break
						// case 2:
						// 	url = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&coord_type=gcj02&src=andr.baidu.openAPIdemo`
						// 	break
						case 1:
							url = `androidamap://viewMap?sourceApplication=appname&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`
							break
						default:
							break
					}
					this.openMapApp(url)
				})
			} else {
				//iOS上获取本机是否安装了百度高德地图，需要在manifest里配置

				//在manifest.json文件app-plus->distribute->apple->urlschemewhitelist节点下添加

				//(如urlschemewhitelist:["iosamap","baidumap"])

				plus.nativeUI.actionSheet(this.actionSheetOption, (e) => {
					switch (e.index) {
						case 1:
							url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`

							break
						case 2:
							url = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&content=${name}&src=ios.baidu.openAPIdemo&coord_type=gcj02`

							break
						case 3:
							url = `iosamap://viewMap?sourceApplication=applicationName&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`

							break
						default:
							break
					}
					this.openMapApp(url)
				})
			}
		},
		openMapApp(url) {
			if (url != '') {
				url = encodeURI(url) //调起手机APP应用
				plus.runtime.openURL(url, (e) => {
					this.$toast('本机未安装指定的地图应用!')
				})
			}
		}
	}
}
